<?php

/**
 * Plugin para enviar mails
 *
 */
class MailEngine {

	
	/**
	* Envia un mail usando la libreria PHPMailer
	*/
	public static function send($from, $fromName, $mailTo, $mailCC, $mailBCC, $subject, $body, $attach = null) {
		require("libs/PHPMailer_v5.1/class.phpmailer.php");
		
		$mail = new PHPMailer(false);
		$mail->IsHTML(true);
		$mail->From = $from;
		$mail->FromName = $fromName;
		//$mail->AddAddress($mailTo);
		
		// add mail TO
		if ($mailTo != null) {
			if (is_array($mailTo)) {
				foreach($mailTo as $to)
					$mail->AddAddress($to);
			} else
				$mail->AddAddress($mailTo);
		}

		// add mail CC
		if ($mailCC != null) { 
			if (is_array($mailCC)) {
				foreach($mailCC as $cc)
					$mail->AddCC($cc);
			} else
				$mail->AddCC($mailCC);
		}
			
		// add mail BCC
		if ($mailBCC != null) {
			if (is_array($mailBCO)) {
				foreach($mailBCO as $bcc)
					$mail->AddBCC($bcc);
			} else
				$mail->AddBCC($bcc);			
		}
		
		// TODO attach file

		$mail->do_debug = 0;
		$mail->Subject = $subject;
		$mail->Body = $body;
		
		$oldErrorSetting = error_reporting(0); // temporarily disable warnings
		$result = $mail->Send();
		error_reporting($oldErrorSetting); // restore error setting
		
		return $result;
		
	}
	
}

